﻿<html>
<body>
  <p>
    Class <strong>
      JPushClient
    </strong>
    <br />
    This class is the core for calling JPush API via official RESTful interfaces.
    There are two major features:
    <ul>
      <li>Send Push message for iOS and/or Android</li>
      <li>Track delivery status via multiple message ID, which returned by JPush Service.</li>
    </ul>
   </p>
  <p>&nbsp;</p>
  <p>
    <strong>Sample:</strong>
  </p>
  <p>Here is a sample based on .NET console application.</p>
  <div class="code">
    <table width="100%" cellspacing="0" cellpadding="0">
      <tr>
      <td>
      <pre xml:space="preserve"><span class="highlight-keyword" style="color: #0000FF;">class</span> Program
 {
      <span class="highlight-keyword" style="color: #0000FF;">static</span> <span class="highlight-keyword" style="color: #0000FF;">void</span> Main(<span class="highlight-keyword" style="color: #0000FF;">string</span>[] args)
      {
          <span class="highlight-keyword" style="color: #0000FF;">var</span> appKey = <span class="highlight-literal" style="color: #CC0000;">"1234567890abcdef"</span>; <span class="highlight-comment" style="color: #006633;">// Your App Key from JPush</span>
          <span class="highlight-keyword" style="color: #0000FF;">var</span> masterSecret = <span class="highlight-literal" style="color: #CC0000;">"1234567890abcdef"</span>; <span class="highlight-comment" style="color: #006633;">// Your Master Secret from JPush</span>
          Dictionary&lt;<span class="highlight-keyword" style="color: #0000FF;">string</span>, <span class="highlight-keyword" style="color: #0000FF;">string</span>&gt; customizedValues = <span class="highlight-keyword" style="color: #0000FF;">new</span> Dictionary&lt;<span class="highlight-keyword" style="color: #0000FF;">string</span>, <span class="highlight-keyword" style="color: #0000FF;">string</span>&gt;();
          customizedValues.Add(<span class="highlight-literal" style="color: #CC0000;">"CK1"</span>, <span class="highlight-literal" style="color: #CC0000;">"CV1"</span>);
          customizedValues.Add(<span class="highlight-literal" style="color: #CC0000;">"CK2"</span>, <span class="highlight-literal" style="color: #CC0000;">"CV2"</span>);
          JPushClient client = <span class="highlight-keyword" style="color: #0000FF;">new</span> JPushClient(appKey, masterSecret, <span class="highlight-keyword" style="color: #0000FF;">false</span>);
          <span class="highlight-keyword" style="color: #0000FF;">var</span> response = client.SendPushMessage(<span class="highlight-keyword" style="color: #0000FF;">new</span> PushMessageRequest
          {
              MessageType = MessageType.Notification,
              Platform = PushPlatform.Android,
              Description = <span class="highlight-literal" style="color: #CC0000;">"DotNET"</span>,
              PushType = PushType.Broadcast,
              IsTestEnvironment = <span class="highlight-keyword" style="color: #0000FF;">true</span>,
              Message = <span class="highlight-keyword" style="color: #0000FF;">new</span> PushMessage
              {
                  Content = <span class="highlight-literal" style="color: #CC0000;">"Hello, this is a test push from .NET. Have a nice day!"</span>,
                  PushTitle = <span class="highlight-literal" style="color: #CC0000;">"A title."</span>,
                  Sound = <span class="highlight-literal" style="color: #CC0000;">"YourSound"</span>,
                  CustomizedValue = customizedValues
              }
          });
          Console.WriteLine(response.ResponseCode.ToString() + <span class="highlight-literal" style="color: #CC0000;">":"</span> + response.ResponseMessage);
          Console.WriteLine(<span class="highlight-literal" style="color: #CC0000;">"Push sent."</span>);
          Console.WriteLine(response.ResponseCode.ToString() + <span class="highlight-literal" style="color: #CC0000;">":"</span> + response.ResponseMessage);
          List&lt;<span class="highlight-keyword" style="color: #0000FF;">string</span>&gt; idToCheck = <span class="highlight-keyword" style="color: #0000FF;">new</span> List&lt;<span class="highlight-keyword" style="color: #0000FF;">string</span>&gt;();
          idToCheck.Add(response.MessageId);
          <span class="highlight-keyword" style="color: #0000FF;">var</span> statusList = client.QueryPushMessageStatus(idToCheck);
          Console.WriteLine(<span class="highlight-literal" style="color: #CC0000;">"Status track is completed."</span>);
          <span class="highlight-keyword" style="color: #0000FF;">if</span> (statusList != <span class="highlight-keyword" style="color: #0000FF;">null</span>)
          {
          <span class="highlight-keyword" style="color: #0000FF;">foreach</span> (<span class="highlight-keyword" style="color: #0000FF;">var</span> one <span class="highlight-keyword" style="color: #0000FF;">in</span> statusList)
              {
                  Console.WriteLine(<span class="highlight-keyword" style="color: #0000FF;">string</span>.Format(<span class="highlight-literal" style="color: #CC0000;">"Id: {0}, Android: {1}, iOS: {2}"</span>, one.MessageId, one.AndroidDeliveredCount, one.ApplePushNotificationDeliveredCount));
              }
          }
          Console.WriteLine(<span class="highlight-literal" style="color: #CC0000;">"Press any key to exit."</span>);
          Console.Read();
      }
  }</pre></td></tr>
    </table>
  </div>
    <p>
    RESTful API reference: <a href="http://docs.jpush.cn/display/dev/Index">http://docs.jpush.cn/display/dev/Index</a>
  </p>
  <p>
    <strong>NOTE:</strong>
    <ul>
      <li>As official document defined, the message ID collection is limited by 1000 in one track request. So if more than 1000 is set in collection for tracking, only the first 1000 can get status information in result.</li>
      <li>Regarding to the possible change of official RESTful API, current client is cliamed to base on v2 version of JPush.</li>
    </ul>
  </p>

</body>
</html>